/*
 * Created by Jesse Phillips
 * Created on Mar 15, 2006
 */
/**
 * A binary tree implementation that lets you add comparable
 * element, retrieve it, and construct a new binary tree that
 * of a comparable object. There are no search or 
 * removel methods.
 *
 * @author Jesse Phillips
 * @see "No barrowed code."
 */
public class BinaryTree/*ans bl*/extends BTDriver/*ans ab*/ {
	private Comparable item;
	public BinaryTree left;
	public BinaryTree right;
	
	/**
	 * Builds a new binary tree holding the given item.
	 * 
	 * @param item The item the tree is to hold.
	 */
	public BinaryTree(Comparable item) {
		this.item = item;
		left=null;
		right=null;
	}
	
	/**
	 * Allows you to add an item to the tree.
	 * 
	 * @param newItem The item to be added.
	 */
	public void add(Comparable newItem) {
/*ans bl*/
		if(newItem.compareTo(item) < 0)
			if(left == null)
				left = new BinaryTree(newItem);
			else
				left.add(newItem);
		else
			if(right == null)
				right = new BinaryTree(newItem);
			else
				right.add(newItem);
/*ans ab*/
	}
	
	/**
	 * Returns the item that this root tree holds.
	 * 
	 * @return the item contand in this root.
	 */
	public Comparable getItem() {
		return item;
	}
}
